<template>
    <!--
        作者 yunding
        时间：2020-06-09
        描述：会员-等级管理-添加等级
    -->
    <el-drawer title="添加资讯" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
        :close-on-press-escape="false" size="700px">
        <el-form size="small" :model="form" ref="form">

            <el-form-item label="资讯名称" :label-width="formLabelWidth" prop="title"
                :rules="[{ required: true, message: '请输入资讯名称' }]" style="width: 500px;">
                <el-input v-model="form.title" placeholder="请输入资讯名称"></el-input>
            </el-form-item>

            <el-form-item label="资讯类型" :label-width="formLabelWidth" prop="type"
                :rules="[{ required: true, message: '请选择资讯类型' }]">
                <el-select v-model="form.type" placeholder="请选择">
                    <el-option label="资讯 " :value="0"></el-option>
                    <el-option label="商学院" :value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="资讯内容" :label-width="formLabelWidth" prop="content"
                :rules="[{ required: true, message: '请选择资讯类型' }]">
                <Uediter :text="form.content" :config="ueditor.config" ref="ue" @contentChange="contentChangeFunc">
                </Uediter>

            </el-form-item>
        </el-form>

        <div style="width: 160px;margin: 0 auto;" class="dialog-footer">
            <el-button @click="dialogFormVisible">取 消</el-button>
            <el-button type="primary" @click="addTag()" :disabled="submit_loading">确 定</el-button>
        </div>
    </el-drawer>
</template>

<script>
import NewsApi from '@/api/news.js';
import Uediter from '@/components/UE.vue';

export default {
    components: {
        /*编辑器*/
        Uediter,
    },
    data() {
        return {
            ueditor: {
                text: '',
                config: {
                    initialFrameWidth: 400,
                    initialFrameHeight: 500
                }
            },
            form: {
                /*昵称*/
                title: '',
                type: 0,
                content: '',
            },
            /*左边长度*/
            formLabelWidth: '120px',
            /*是否显示*/
            dialogVisible: false,
            /*是否正在提交*/
            submit_loading: false,
        };
    },
    props: ['open_edit', 'form'],
    created() {
        this.dialogVisible = this.open_edit;
    },
    methods: {
        /*获取富文本内容*/
        contentChangeFunc(e) {
            this.form.content = e;
        },
        /*添加等级*/
        addTag() {
            let self = this;
            let params = this.form;
            self.$refs.form.validate((valid) => {
                if (valid) {
                    self.submit_loading = true;
                    NewsApi.edit_item(params, true).then(data => {
                        self.submit_loading = false;
                        self.$message({
                            message: data.msg,
                            type: 'success'
                        });
                        self.dialogFormVisible(true);
                    })
                        .catch(error => {
                            self.submit_loading = false;
                        });
                }
            });
        },
        /*关闭弹窗*/
        dialogFormVisible(e) {
            if (e) {
                this.$emit('closeDialog', {
                    type: 'success',
                    openDialog: false
                })
            } else {
                this.$emit('closeDialog', {
                    type: 'error',
                    openDialog: false
                })
            }
        }

    }
};
</script>

<style></style>
